<template>
  <el-dialog
    :title="'机构备案信息查询'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="150px">

    <el-form-item label="登记中心" prop="djzx" >
      <el-select v-model="dataForm.djzx" placeholder="登记中心" style="width:100%">
          <el-option
            v-for="item in dataForm.bankList"
            :key="item.bankid"
            :label="item.bankname"
            :value="item.bankid">
          </el-option>
      </el-select>
    </el-form-item>




    <el-form-item label="现机构代码" prop="orgid" >
      <el-select
          v-model="dataForm.orgid"
          clearable
          filterable
          style="width:100%;"
          remote
      
          placeholder="输入抵押权人代码或名称"
          :remote-method="remoteMethod"
          :loading="loading">
          <el-option
            v-for="item in list"
            :key="item.branchid"
            :label="item.branchname"
            :value="item.branchid">
          </el-option>
        </el-select>
    </el-form-item>



    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        list: [],
        dataForm: {
          seqno: 0,
          djzx: '',

          orgid: '',

          bankList: []
        },
        dataRule: {
          djzx: [
            { required: true, message: '登记中心不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {

      remoteMethod(query) {
        if (query !== '') {
          this.loading = true;

          this.$http({
            url: this.$http.adornUrl(`/sys/user/branch/search`),
            method: 'get',
            params: this.$http.adornParams({
              "key": query
            })
          }).then(({data}) => {
            this.loading = false;
            if (data && data.code === 0) {
                this.list = data.list;
            }
          })     
          
        } else {
          this.list = [];
        }
      },

      init (id) {
        this.dataForm.seqno = id || 0
        this.visible = true

        this.$http({
          url: this.$http.adornUrl(`/bdc/bdcorgchginfo/item/list`),
              method: 'get',
              params: this.$http.adornParams()
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.dataForm.bankList = data.bankList

            }
        })

        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.seqno) {
            this.$http({
              url: this.$http.adornUrl(`/bdc/bdcorgchginfo/info/${this.dataForm.seqno}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.djzx = data.bdcOrgchginfo.bdcno
                this.dataForm.obankid = data.bdcOrgchginfo.obankid
                this.dataForm.oriorgname = data.bdcOrgchginfo.oriorgname
                this.dataForm.oriorgid = data.bdcOrgchginfo.oriorgid
                this.dataForm.orgname = data.bdcOrgchginfo.orgname
                this.dataForm.orgid = data.bdcOrgchginfo.orgid
                this.dataForm.chgtype = data.bdcOrgchginfo.chgtype
                this.dataForm.chgtime = data.bdcOrgchginfo.chgtime
                this.dataForm.examstate = data.bdcOrgchginfo.examstate
                this.dataForm.examdesc = data.bdcOrgchginfo.examdesc
                this.dataForm.remark = data.bdcOrgchginfo.remark
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {          
            this.$http({
              url: this.$http.adornUrl(`/bdc/bdcorgchginfo/querybatch`),
              method: 'post',
              data: this.$http.adornData({
                'djzx': this.dataForm.djzx,
                'orgid': this.dataForm.orgid
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
